import { defineStore } from "pinia"
import request from '@/utils/request'
import { ApiRes, BannerItem, GoodsItem, HotGoods, Brand } from '@/types/data'

const useHomeStore = defineStore('home', {
    state: () => ({
        bannerList: [] as BannerItem[],
        newGoodsList: [] as GoodsItem[],
        hotGoodsList: [] as HotGoods[],
        brandList: [] as Brand[],
    }),
    actions: {
        async getBannerList() {
            const res = await request.get<ApiRes<BannerItem[]>>('/home/banner')
            this.bannerList = res.data.result
        },
        async getNewGoodsList() {
            const res = await request.get<ApiRes<GoodsItem[]>>('/home/new')
            this.newGoodsList = res.data.result
        },
        async getHotGoodsList() {
            const res = await request.get<ApiRes<HotGoods[]>>('/home/hot')
            this.hotGoodsList = res.data.result
        },
        async getBrandList() {
            const res = await request.get<ApiRes<Brand[]>>('/home/brand')
            console.log(res)
            this.brandList = res.data.result
        },
    },
    getters: {
    }
})

export default useHomeStore